<?php 
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$re=user_login();
if($re['err']=='no_login'){direct('login.php?t='.time());exit;}
if($re['err']!='ok'){die($re['err']);}
$user=$re['user'];
$shop_id=$re['shop_id'];
$shop=get_shop();
$set=get_set();
$ac=g('ac');
if($ac=='creat_new'){
$arr['title']='新建活动';
$arr['state']=0;
$arr['img']=$cfg['no_img'];
$arr['start']=time()+3600;
$arr['end']=time()+3600*24*30;
$arr['shop_id']=$shop['id'];
$arr['user_id']=$user['id'];
$id=insert($cfg['e'].'hd',$arr);
if($id){echo '<script>location.href="?url=hd_edit&left_c=hd_list&id='.$id.'"</script>';exit;}
}

$id=g('id');

if($id){
if(!is_numeric($id)){die('请指定活动');}
$sql='select * from '.$cfg['e'].'hd where id="'.$id.'" and shop_id="'.$shop['id'].'" ';
if(!$user['shop_id']){$sql.=' and user_id="'.$user['id'].'"';}
$l=db1($sql);
if(!$l){die('抱歉，没有找到活动，或者您没有编辑的权限');}

}



if($l['html']){
$html=unserialize(base64($l['html']));
}


$bt='<icon class="icon icon-shanchu" onclick="html_ac($(this))" c="del"></icon>';

$bt.='<icon class="icon icon-chevron-up" onclick="html_ac($(this))" c="up"></icon>';
$bt.='<icon class="icon icon-chevron-down" onclick="html_ac($(this))" c="down"></icon>';
$bt.='<icon class="icon icon-backtop" onclick="html_ac($(this))" c="top"></icon>';
?>
<style>
hd_box{float:left;width:100%;background:#fff;min-height:50vh;margin-right:20px}
hd_box handle{float:left;width:100%;height:36px;line-height:36px;padding-left:10px;padding-right:10px;font-weight:bold;font-size:16px;border-bottom:1px solid #eee;}
hd_box handle a{margin-left:10px;float:right;height:28px;line-height:28px;margin-top:4px;background:#006eff;color:#fff;padding-left:10px;font-weight:normal;padding-right:10px;font-size:12px;color:#fff;}
img_box{float:left;width:100%;height:250px;overflow:hidden;}
img_box img_item{float:left;width:100%;height:100%;display:flex;flex-direction:row;}
img_item im{float:left;width:100%;height:100%}
mm{display:flex;flex-direction:row;}
x_num{position:absolute;width:100%;display:flex;justify-content:center;top:200px;z-index:100;left:0;height:20px;}
x_num a{float:left;width:10px;height:10px;background:#ccc;border-radius:50%;margin:5px;}
x_num .select{background:crimson;}
select_bt{position:absolute;top:10px;z-index:100;right:10px}
select_bt a{float:right;padding-left:15px;padding-right:15px;height:28px;line-height:28px;background:#006eff;color:#fff;}

ll{float:left;width:100%;margin-top:5px;padding-left:10px;padding-right:10px;min-height:40px;}
ll input{float:left;width:100%;height:40px;line-height:40px;}
ll textarea{float:left;width:100%;height:100px;outline:none;background:#efefef;border:none}
tool_box{float:left;width:100%;margin-top:10px;}
tool_box view{float:left;width:20%;height:45px;line-height:20px;text-align:center;font-size:28px !important;margin-top:5px}
tool_box text{position:absolute;width:100%;left:0;bottom:0;font-size:10px;color:#999}

html_box{float:left;width:100%;padding:10px}
html_item{float:left;width:100%;margin-top:10px}
html_tool{float:left;width:100%;height:30px;line-height:30px;}
html_item textarea{float:left;width:100%;outline:none;background:#efefef;border:none;height:120px}

html_item .big{float:left;width:100%;}
heng_box{float:left;width:100%;height:200px;overflow:hidden;}
heng_item{float:left;width:100%;height:100%;display:flex;flex-direction:row;}
heng_item item{float:left;width:100%;height:100%;}
h_ido{position:absolute;width:100%;bottom:20px;display:flex;justify-content:center;}
h_ido a{float:left;width:10px;height:10px;background:#ccc;border-radius:50%;margin:5px;}
h_ido .select{background:crimson;}

small_img{float:left;width:100%;}
small_item{float:left;width:33.33%;padding:5px;}
small_item text{position:absolute;right:5px;top:5px;font-size:18px;}
small_item item{float:left;width:100%;height:100px;border-radius:5px}
html_tool b{font-size:15px;}
html_tool icon{float:right;margin:5px;margin-right:5px;width:20px;height:20px;background:#efefef;border-radius:5px;line-height:20px;text-align:center;}

tag_box{float:left;width:100%;margin-top:10px;padding-left:10px;padding-right:10px}
tag_box tag{float:left;padding-left:10px;padding-right:10px;height:28px;line-height:28px;background:rgba(0,255,0,0.1);margin:5px;border-radius:5px;}
tag_box tag text{position:absolute;right:-5px;top:-10px;z-index:100;}

fen_data{float:left;width:100%;margin-top:10px;padding-left:10px;padding-right:10px;}
fen_data item{float:left;width:100%;height:80px;background:#efefef;border-radius:8px;padding-left:80px;}
fen_data img{position:absolute;width:60px;height:60px;left:10px;top:10px}
fen_data nickname{float:left;width:100%;height:20px;line-height:20px;margin-top:10px;font-size:17px;font-weight:bold;}
fen_data info{float:left;width:100%;height:20px;line-height:20px;font-size:13px;background:none}
fen_data text{position:absolute;top:-5px;right:-5px;z-index:10000;font-size:20px !important;}
fen_data btx,nuo_box btx{float:left;width:100%;padding-right:20px;}
fen_data btx a,nuo_box btx a{float:right;height:25px;line-height:25px;padding-left:10px;padding-right:10px;background:#006eff;color:#fff;margin-left:10px;}
nuo_box{float:left;width:100%;margin-top:10px;padding-left:10px;padding-right:10px;}
nuo_box item{float:left;width:100%;padding:10px;background:#efefef;border-radius:8px;line-height:20px}
nuo_box b{float:left;width:100%;font-size:16px;margin-bottom:5px;}
nuo_box text{position:absolute;top:-5px;right:-5px;z-index:10000;font-size:20px !important;}
pro_list{float:left;width:100%;padding-left:10px;padding-right:10px;}
pro_item{float:left;width:100%;background:#efefef;min-height:100px;padding:10px;padding-left:100px;border-radius:5px;margin-top:10px}
pro_img{position:absolute;width:80px;height:80px;left:10px;top:10px;}
pro_item input{float:left;width:100%;height:20px;line-height:20px;background:#fff;margin-bottom:5px;}
pro_item index a{float:right;height:26px;line-height:26px}
x_box{float:left;width:100%;padding-left:10px;padding-right:10px;}
pro_item view{float:left;width:100%;height:20px;line-height:20px;}
x_box input{background:none}

x_btx{float:left;width:100%;padding-left:50px;padding-right:50px;}
x_btx a{float:left;width:100%;height:40px;line-height:40px;background:#006eff;color:#fff;text-align:center;}
x_box view{float:left;width:100%;height:40px;line-height:40px;font-size:16px;}

</style>
<hh><b>团购活动编辑</b></hh>
<help style="margin-top:0">团购</help>
<index style="margin-top:10px;padding-left:10px;"><a class="m" id="save_bt" onclick="save()">保存更改</a></index>
<mm>

<hd_box>
<img_box >
<?php 
if(!$l['img']){$l['img']=$cfg['no_img'];}
$img=explode("||",$l['img']);$img_num=0;
foreach($img as $v){
if($v){
$im=get_img($v,'_480');
$h.= '<im style="background:url('.$im.') no-repeat center;background-size:cover;"></im>';
$ido.='<a class="item_'.$img_num.'"></a>';
$img_num++;
}
}
echo '<img_item style="width:'.($img_num*100).'%">'.$h.'</img_item>';
?>
</img_box>
<?php 
?>
<x_num><?php echo $ido;?></x_num>
<select_bt><a onclick="right({title:'选择活动主图',url:'select_img.php?action=select_main_img($(this))&max=5',width:'75vw'})">选择主图</a></select_bt>
<ll>
<input placeholder="活动标题" value="<?php echo base64($l['title'])?>" onchange="val_change($(this))" c="title">
</ll>
<ll>
<textarea placeholder="活动介绍" onchange="val_change($(this))" c="info"><?php echo base64($l['info'])?></textarea>
</ll>

<tag_box>
<?php 
if($l['tag']){
$tag=unserialize(out($l['tag']));
foreach($tag as $v){
echo '<tag val="'.$v.'">'.$v.'<text class="icon icon-roundclosefill" onclick="tag_del($(this))"></text></tag>';
}
}
?>
</tag_box>

<?php 
if($l['fen_data']){
$fen_data=unserialize(base64($l['fen_data']));
echo '<fen_data><item>
<img src="'.$fen_data['img'].'">
<nickname>'.$fen_data['name'].'</nickname>
<info>'.$fen_data['info'].'</info>
<text class="icon icon-roundclosefill" onclick="data_clean($(this))" c="fen_data"></text>
</item></fen_data>';
}

if($l['nuo_data']){
echo '<nuo_box>';
echo '<item><b>门店承诺</b><text class="icon icon-roundclosefill" onclick="data_clean($(this))" c="nuo_data"></text>'.$l['nuo_data'].'</item>';
echo '</nuo_box>';

}


?>



<tool_box>
<view class="icon icon-paizhao" onclick="right({title:'选择大图',url:'./select_img.php?action=html_bg_img($(this))',width:'75vw'})" ><text>大图</text></view>
<view class="icon icon-qiehuan" onclick="right({title:'选择大图',url:'./select_img.php?action=html_heng_img($(this))&max=5',width:'75vw'})"><text>轮播图</text></view>
<view class="icon icon-fenlei11" onclick="right({title:'选择大图',url:'./select_img.php?action=html_small_img($(this))&max=6',width:'75vw'})"><text>小图</text></view>
<view class="icon icon-bianji" onclick="textaera_add()"><text>文本</text></view>
<view class="icon icon-shipin" onclick="video_edit()"><text>视频</text></view>
<view class="icon icon-biaoqian1" onclick="tag_win()"><text>标签</text></view>
<view class="icon icon-tianjiahaoyou" onclick="right({title:'加粉列表',url:'fen_data.php',width:'500px'})"><text>加粉</text></view>
<view class="icon icon-renzhengdunpaianquanbaozhangzhibao-xianxing" onclick="right({title:'承诺列表',url:'nuo_data.php',width:'500px'})"><text>承诺</text></view>
</tool_box>

<html_box>

</html_box>


</hd_box>
<hd_box>
<handle>活动商品<a onclick="right({title:'快速创建商品',url:'select_img.php?action=quick_creat_pro($(this))',width:'75vw'})">快速创建商品</a>
<a onclick="right({title:'导入商品',url:'hd_pro_list.php?action=pro_ac($(this))&m=pro',width:'1000px'})">导入商品</a></handle>
<pro_list>
<?php 
if($l['pro']){
$pro=unserialize(out($l['pro']));//活动商品
//print_r($pro);
$pros=get_pros($pro,$l['zk']);
if($pros){
foreach($pros as $v){
$img=get_img($v['img'],'_240');
echo '<pro_item c="pro_'.$v['id'].'">';
echo '<pro_img style="background:url('.$img.') no-repeat center;background-size:cover;"></pro_img>';
echo '<input placeholder="商品名称" value="'.base64($v['title']).'" c="title" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="价格" value="'.$v['price'].'" c="price" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="原价" value="'.$v['old'].'" c="old" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="库存" value="'.$v['total'].'" c="total" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<index>

<a class="m b" onclick="pro_edit($(this))" i="'.$v['id'].'">修改</a>
<a class="icon m icon-backtop " onclick="pro_ac($(this))" c="up" i="'.$v['id'].'"></a>
<a class="icon m icon-shanchu " onclick="pro_ac($(this))" c="del" i="'.$v['id'].'"></a>
</index>';
echo '</pro_item>';
}
}


}else{
no_data('您还没有商品');
}


?>

</pro_list>

</hd_box>

<hd_box>
<handle>活动设置</handle>
<x_box>
<l><text>开始时间</text>
<view ><?php echo date('Y-m-d H:i:s',$l['start']);?></view>
</l>
<l><text>结束时间</text>
<view ><?php echo date('Y-m-d H:i:s',$l['end']);?></view>
</l>


</x_box>    
    

    
<handle>秒杀<a class="m b" onclick="right({title:'选择秒杀商品',url:'hd_pro_list.php?action=choise_pro($(this),1)',width:'1000px'})">选择商品</a></handle>

<x_box>
<l><text>秒杀标题</text>
<input placeholder="秒杀的标题" onchange="val_change($(this))" c="miao_title" value="<?php echo $l['miao_title']?>" >
</l>

<l><text>秒杀价</text>
<input placeholder="商品的秒杀价" onchange="val_change($(this))" c="miao_price" value="<?php echo $l['miao_price']?>" type="number">
</l>
<l><text>秒杀数量</text>
<input placeholder="秒杀商品数量" onchange="val_change($(this))" c="miao_total" value="<?php echo $l['miao_total']?>" type="number">
</l>

<?php 
if($l['miao_pro']){
$pro=get_miao_pro($l['miao_pro']);
echo '<pro_item>';
echo '<pro_img style="background:url('.$pro['img'].') no-repeat center;background-size:cover;"></pro_img>';
echo '<view>'.$pro['title'].'</view>';
echo '<view>'.$l['miao_price'].'</view>';
echo '<index>
<a class="m b" onclick="hui_over($(this))" c="miao_pro">取消</a>
</index>';
echo '</pro_item>';
}else{
echo '<x_btx><a onclick="right({title:\'选择秒杀商品\',url:\'hd_pro_list.php?action=choise_pro($(this),1)\',width:\'1000px\'})">选择秒杀商品</a></x_btx>';
}
?>
</x_box>


<handle>满赠<a class="m b" onclick="right({title:'选择满赠商品',url:'hd_pro_list.php?action=choise_pro($(this),2)',width:'1000px'})">选择商品</a></handle>

<x_box>
<l><text>满赠标题</text>
<input placeholder="满赠标题" onchange="val_change($(this))" c="mz_title" value="<?php echo $l['mz_title']?>" >
</l>

<l><text>满金额</text>
<input placeholder="满多少钱赠" onchange="val_change($(this))" c="mz_price" value="<?php echo $l['mz_price']?>" type="number">
</l>
<l><text>满赠数量</text>
<input placeholder="满赠商品数量" onchange="val_change($(this))" c="mz_total" value="<?php echo $l['mz_total']?>" type="number">
</l>


<?php 
if($l['mz_pro']){
$pro=get_mz_pro($l['mz_pro']);
echo '<pro_item>';
echo '<pro_img style="background:url('.$pro['img'].') no-repeat center;background-size:cover;"></pro_img>';
echo '<view>'.$pro['title'].'</view>';
echo '<view>满'.$l['mz_price'].'赠</view>';
echo '<index>
<a class="m b" onclick="hui_over($(this))" c="mz_pro">取消</a>
</index>';
echo '</pro_item>';
}else{
echo '<x_btx><a onclick="right({title:\'选择满赠商品\',url:\'hd_pro_list.php?action=choise_pro($(this),2)\',width:\'1000px\'})">选择秒杀商品</a></x_btx>';
}
?>
</x_box>
<x_box>
    <handle>增加虚拟订单</handle>
    <l><text>增加人数</text>
        <input placeholder="请输入增加人数" onchange="val_change($(this))" c="virtual_people" value="<?php echo $l['virtual_people']?>" type="number">
    </l>
</x_box>


</hd_box>
</mm>









<script>
window.html_obj=<?php if($html){echo json_encode($html);}else{echo '{}';}?>;
window.save_list={}

$(document).ready(function(){
$('x_num .item_0').addClass('select');
window.main_bg_scroll = new IScroll("img_box", {snap: true,scrollX: true,snapSpeed: 800,});
window.main_bg_scroll.on("scrollEnd", function () {
var page=this.currentPage.pageX;
$("x_num a").removeClass('select');
$('x_num .item_'+page).addClass('select');
});

html_init();

<?php 
if($heng_id){
foreach($heng_id as $v){    
echo '$("#'.$v.' h_ido .item_0").addClass("select");
window.'.$v.' = new IScroll("#'.$v.' heng_box", {snap: true,scrollX: true,snapSpeed: 800,});
window.'.$v.'.on("scrollEnd", function () {
var page=this.currentPage.pageX;
$("#'.$v.' h_ido a").removeClass("select");
$("#'.$v.' h_ido .item_"+page).addClass("select");
});
';
}}


?>

});


function html_bg_img(o){//添加大图
var img=o.attr('img_750');
if(!window.html_obj){window.html_obj={}}
var t=(new Date()).getTime();
window.html_obj['item_'+t]={type:'big',value:img}
html_init('html');
msg('大图添加成功，请保存更改');
}


function need_save(ac){
if(!ac){$('#save_bt').removeClass('b');window.save_list={}}else{
$('#save_bt').addClass('b');
window.save_list[ac]=ac;
window.can_save=1;
}
}

function html_ac(o){
var obj=o.parent().parent();
var c=o.attr('c');
var id=obj.attr('id');
switch(c){
case 'del':
delete(window.html_obj[id]);
html_init('html');
break;
case 'up':
var temp_idx='';var temp_id='';
for(var i in window.html_obj){
if(id==i){temp_id=temp_idx;}
temp_idx=i;
}
if(!temp_id){return;}//最顶端
var temp=window.html_obj[id];
window.html_obj[id]=window.html_obj[temp_id];
window.html_obj[temp_id]=temp;
html_init('html')
break;

case 'down':
var temp_idx=0;var temp_id='';
for(var i in window.html_obj){
if(temp_idx==1){temp_id=i;temp_idx=0;}
if(id==i){temp_idx=1;}
}
if(!temp_id){return;}//最顶端
var temp=window.html_obj[id];
window.html_obj[id]=window.html_obj[temp_id];
window.html_obj[temp_id]=temp;
html_init('html')
break;
case 'top':
var temp_id='';
for(var i in window.html_obj){
if(!temp_id){temp_id=i;}
}
if(!temp_id){return;}//最顶端
var temp=window.html_obj[id];
window.html_obj[id]=window.html_obj[temp_id];
window.html_obj[temp_id]=temp;
html_init('html')
break;
}
}



function html_init(ac){
if(!window.html_obj){window.html_obj={}}
window.heng_obj={}
var num=Object.keys(window.html_obj).length;
if(num==0){$('html_box').html('您尚未编辑活动介绍');return;}
var html='';
for(var i in window.html_obj){
var obj=window.html_obj[i];
html+='<html_item id="'+i+'">';

switch(obj.type){
case 'text':
html+='<html_tool><b>文本</b><?php echo $bt?></html_tool>';
html+='<textarea onchange="html_text_change($(this))" i="'+i+'">'+obj.value+'</textarea>';
break; //text
case 'big':
html+='<html_tool><b>大图</b><?php echo $bt?></html_tool>';
html+='<img class="big" src="'+obj.value+'">';
break;//big

case 'small':
html+='<html_tool><b>小图</b><?php echo $bt?></html_tool>';
html+='<small_img>';
for(var j in obj.value){
html+='<small_item><item style="background:url('+obj.value[j].img_480+') no-repeat center;background-size:cover;"><text class="icon icon-roundclosefill" onclick="small_item_del($(this))" i="'+j+'" o="'+i+'"></text></item></small_item>';
}
html+='</small_img>';
break;//小图

case 'heng':
html+='<html_tool><b>轮播图</b><?php echo $bt?></html_tool>';
var heng_num=Object.keys(obj.value).length;
var h_ido='';var h_id=0;
html+='<heng_box>';
html+='<heng_item style="width:'+(heng_num*100)+'%">';
for(var j in obj.value){
html+='<item style="background:url('+obj.value[j]['img_750']+') no-repeat center;background-size:cover;"></item>';
h_ido+='<a class="item_'+h_id+'"></a>';
h_id++;
}

html+='</heng_item></heng_box><h_ido>'+h_ido+'</h_ido>';

window.heng_obj[i]=i;
break;


}



html+='</html_item>';
}
$('html_box').html(html);
var heng_num=Object.keys(window.heng_obj).length;

if(heng_num>0){
for(var i in window.heng_obj){
scroll_it(i);
}
}
if(ac){need_save(ac);}

}

function small_item_del(o){
var id=o.attr('o');
var i=o.attr('i');
var obj=window.html_obj[id];
delete(obj.value[i]);
if(Object.keys(obj.value).length==0){
delete(window.html_obj[id])
}else{
window.html_obj[id]=obj;
}
html_init('html');
}

function scroll_it(id){
var h='$("#'+id+' h_ido .item_0").addClass("select");'; 
h+='window.'+id+' = new IScroll("#'+id+' heng_box", {snap: true,scrollX: true,snapSpeed: 800,});';
h+='window.'+id+'.on("scrollEnd", function () {var page=this.currentPage.pageX;$("#'+id+' h_ido a").removeClass("select");$("#'+id+' h_ido .item_"+page).addClass("select");});';

eval(h)
}

function html_heng_img(){

var img_data={}
for(var i in window.is_select_img){
var obj=$('.'+i);
var img=obj.attr('img_750');
img_data[i]={img_750:img}
}
var t=(new Date()).getTime();
window.html_obj['item_'+t]={type:'heng',value:img_data}
console.log(window.html_obj);
html_init('html');
right_close();
}

function html_small_img(){

var img_data={}
for(var i in window.is_select_img){
var obj=$('.'+i);
var img=obj.attr('img_480');
img_data[i]={img_480:img,img_240:obj.attr('img_240'),img_750:obj.attr('img_750')}
}
var t=(new Date()).getTime();
window.html_obj['item_'+t]={type:'small',value:img_data}
console.log(window.html_obj);
html_init('html');
right_close();
}

function textaera_add(){
var t=(new Date()).getTime();
window.html_obj['item_'+t]={type:'text',value:''}
html_init('html');
}

function html_text_change(o){
var id=o.attr('i');
window.html_obj[id]['value']=o.val();
html_init('html');
}

function save(){///保存活动
console.log(window.save_list);
if(Object.keys(window.save_list).length==0){msg('没有可以保存的');return;}
var data={}
for(var i in window.save_list){
switch(i){
case 'html':
data['html']=window.html_obj;
break;
}

}
console.log(data);
post('hd_save',data,'<?php echo $l['id']?>',function(res){
    main_load();
    msg('保存成功');
    window.can_save=0;
});

}


function select_main_img(){
if(!window.is_select_img){window.is_select_img={}}
if(Object.keys(window.is_select_img).length==0){msg('请选择图片');return;}
var img='';
for(var i in window.is_select_img){
var im=$('.'+i).attr('x');
img+=im+'||'
}
var data={img:img}
post('hd_save',data,'<?php echo $l['id']?>',function(res){
    main_load();
    right_close()
});
}


function val_change(o,cc,ac){
var c=o.attr('c');
var val=o.val();
if(cc){val=o.attr('val');if(!val){val=''}}
var data={[c]:val}
post('hd_save',data,'<?php echo $l['id']?>',function(res){
    if(ac){main_load();}
    msg('保存成功')
});
}

function tag_win(){
var h='<l><text>标题</text><input placeholder="请输入标签" id="tag_text"></l>';
h+='<l><index><a class="m b" onclick="tag_add($(this))">提交标签</a></index></l>';
win({title:'输入标签',html:h,width:600,id:'tag_box'})
}

function tag_add(){
var val=$('#tag_text').val();
if(!val){msg('请输入标签');return;}
var h='<tag val="'+val+'">'+val+'<text class="icon icon-roundclosefill" onclick="tag_del($(this))"></text></tag>';
$('tag_box').append(h);
tag_save();
}

function tag_save(){
var tag={};
$('tag_box tag').each(function(){
var val=$(this).attr('val');
if(val){
tag[[val]]=val;
}
});
if(Object.keys(tag).length==0){tag='none'}
var data={tag:tag}
post('hd_save',data,'<?php echo $l['id']?>',function(res){
    msg('保存成功')
});
}

function tag_del(o){
o.parent().remove();
tag_save();
}


function data_clean(o){
var c=o.attr('c');
if(!confirm("是否清楚数据?")){return;}
var data={[c]:'clean'}
post('hd_save',data,'<?php echo $l['id']?>',function(res){
main_load();
});
}


function pro_ac(o){
var id=o.attr('i');
var c=o.attr('c');
if(c=='del'){
if(!confirm("是否删除商品，删除不会删除商品的内容?")){return;}
}
if(window.can_save==1){
if(!confirm("您有活动没有保存，请保持后继续?")){return;}
}
var data={ac:c,id:id}
post('hd_pro_ac',data,'<?php echo $l['id']?>',function(res){
    main_load();
    if(c=='add'){msg('添加成功');}
});
    
}


function pro_change(o){
var id=o.attr('i');
var c=o.attr('c');
var val=o.val();
post('pro_change',{[c]:val},id,function(res){
    msg('修改成功');
})
}

function quick_creat_pro(o){
var img=o.attr('x');
var data={img:img,state:1}
post('quick_creat_pro',data,'',function(res){
    if(res.err=='ok'){
    var dd={ac:'add',id:res.id}
    post('hd_pro_ac',dd,'<?php echo $l['id']?>',function(res){
    main_load();
    msg('添加成功')
});
}
});
}


function choise_pro(o,ac){
var id=o.attr('i');var c='';
if(ac==1){c='miao_pro';}else{c='mz_pro';}
var data={[c]:id};
post('hd_save',data,'<?php echo $l['id']?>',function(res){
    main_load();
    right_close()
});
}

function hui_over(o){
  var c=o.attr('c'); 
  var data={[c]:'clean'}
  post('hd_save',data,'<?php echo $l['id']?>',function(res){
    main_load();
   
});
}

</script>